package com.zline.foodraise.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.zline.foodraise.R;

//自定义加载框
public class LoadingProgressDialog extends Dialog {
    private static final String LOG_TAG = LoadingProgressDialog.class.getSimpleName();


    public LoadingProgressDialog(Context context) {
        super(context);
    }

    public LoadingProgressDialog(Context context, int theme) {
        super(context, theme);

    }

    /**
     * 当窗口焦点改变时调用
     */
    public void onWindowFocusChanged(boolean hasFocus) {
        ImageView imageView = (ImageView) findViewById(R.id.loading_progress_iv);
        // 获取ImageView上的动画背景
        AnimationDrawable spinner = (AnimationDrawable) imageView.getBackground();
        // 开始动画
        spinner.start();
    }

    /**
     * 弹出自定义ProgressDialog
     *
     * @param context 上下文	 * @param message
     *                提示
     */
    public static LoadingProgressDialog init(Context context) {
        LoadingProgressDialog dialog = new LoadingProgressDialog(context, R.style.custom_progress);
        dialog.setContentView(R.layout.dialog_custom_progress);

        // 按返回键是否取消
        dialog.setCancelable(true);
        //点击对话框以外是否消失
        dialog.setCanceledOnTouchOutside(false);
        // 设置居中
        dialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        // 设置背景层透明度
        lp.dimAmount = 0.6f;
        dialog.getWindow().setAttributes(lp);
        return dialog;
    }
}
